package org.heart.springsecurity.exceptionHandler;


import org.heart.springsecurity.exceptions.CustomExceptions;
import org.heart.springsecurity.result.ApiResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 捕获全局自定义异常类
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(CustomExceptions.CustomUserNotFoundException.class)
    @ResponseBody
    public String handleUsernameNotFoundException() {
        return ApiResponse.fail("账户不存在");
    }

    @ExceptionHandler(CustomExceptions.CustomPhoneException.class)
    @ResponseBody
    public String handleUsernameNotFoundException(CustomExceptions.CustomPhoneException e) {
        return ApiResponse.fail(e.getMessage());
    }

}